﻿using System;

namespace Opo.Perspective.Core
{
    /// <summary>
    /// 
    /// </summary>
    public static class MailCacheFactory
    {
        /// <summary>
        /// Gets an instance of a MailCache.
        /// </summary>
        /// <param name="args">Arguments for the constructor (e.g. path to xml files)</param>
        /// <returns>An instance of <see cref="MailCacheBase">MailCacheBase</see></returns>
        public static MailCache GetInstance(params string[] args)
        {
            return MailCacheFactory.GetInstance("XmlCacheProvider", args);
        }
        /// <summary>
        /// Gets an instance of a MailCache.
        /// </summary>
        /// <param name="typeName">Typen name of the MailCache</param>
        /// <param name="args">Arguments for the constructor (e.g. path to xml files)</param>
        /// <returns>An instance of <see cref="MailCache">MailCache</see></returns>
        public static MailCache GetInstance(string typeName, params string[] args)
        {
            Type t = Type.GetType(typeName);
            if (!t.IsAssignableFrom(typeof(MailCache)))
            {
                throw new ArgumentException(typeName + " is not a valid MailCache");
            }
            MailCache mailCache = (MailCache)Activator.CreateInstance(t, args);
            return mailCache;
        }
    }
}
